﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

namespace MovieSystem.Banco
{
    public class EntGenero
    {
        private int intCategoriaId = 0;
        
        public int Id
        {
            get { return intCategoriaId; }
            set { intCategoriaId = value; }
        }

        private string strCategoriaDecricao = "";

        public string Descricao
        {
            get { return strCategoriaDecricao; }
            set { strCategoriaDecricao = value; }
        }

        public Boolean Inserir()
        {

            int intNumero = 0;
            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("Insert into genero (descricaoGenero) values ('" + this.Descricao + "');", EntConexao.bdConn);
                intNumero = commS.ExecuteNonQuery();

                EntConexao.FecharConexao();

            }


            return true;

        }

        public Boolean Alterar()
        {

            int intNumero = 0;
            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("update genero set descricaoGenero = '" + this.Descricao + "' where idGenero = " + this.Id + ";", EntConexao.bdConn);
                intNumero = commS.ExecuteNonQuery();

                EntConexao.FecharConexao();

            }


            return true;

        }

        public Boolean Excluir()
        {

            int intNumero = 0;
            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("delete from genero where idGenero = " + this.Id + ";", EntConexao.bdConn);
                intNumero = commS.ExecuteNonQuery();

                EntConexao.FecharConexao();

            }


            return true;

        }

        public EntGenero BuscaPorId(string parametro)
        {
            EntGenero oGenero = new EntGenero();

            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("SELECT * FROM genero where idGenero =" + parametro + "", EntConexao.bdConn);
                MySqlDataReader reader = commS.ExecuteReader();

                while (reader.Read())
                {
                    oGenero = new EntGenero();
                    oGenero.Id = Convert.ToInt32(reader["idGenero"].ToString());
                    oGenero.Descricao = reader["descricaoGenero"].ToString();

                }

                EntConexao.FecharConexao();
            }
            return oGenero;
        }

        public List<EntGenero> BuscaPorParametro(string parametro)
        {
            List<EntGenero> lGeneros = new List<EntGenero>();

            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("SELECT * FROM genero where descricaoGenero='" + parametro + "'", EntConexao.bdConn);
                MySqlDataReader reader = commS.ExecuteReader();

                while (reader.Read())
                {
                    EntGenero oGenero = new EntGenero();
                    oGenero.Id = Convert.ToInt32(reader["idGenero"].ToString());
                    oGenero.Descricao = reader["descricaoGenero"].ToString();
                    lGeneros.Add(oGenero);

                }

                EntConexao.FecharConexao();
            }
            return lGeneros;
        }

        public List<EntGenero> BuscaTodas()
        {
            List<EntGenero> lGeneros = new List<EntGenero>();

            if (EntConexao.AbrirConexao())
            {
                MySqlCommand commS = new MySqlCommand("SELECT * FROM genero;", EntConexao.bdConn);
                MySqlDataReader reader = commS.ExecuteReader();

                while (reader.Read())
                {
                    EntGenero oGenero = new EntGenero();
                    oGenero.Id = Convert.ToInt32(reader["idGenero"].ToString());
                    oGenero.Descricao = reader["descricaoGenero"].ToString();
                    lGeneros.Add(oGenero);

                }

                EntConexao.FecharConexao();
            }
            return lGeneros;
        }
    }
}
